﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GJReminder.Utils;

using GCalendar = Google.GData.Calendar;
using Google.GData.Extensions;

namespace GJReminder.Model
{
    public class EventDataModel
    {
        private GCalendar.EventEntry m_entry;
        private When m_when;
        private string m_locationStringCache;

        public string Title
        {
            get
            {
                return m_entry.Title.Text;
            }
            private set
            {
                m_entry.Title.Text = value;
            }
        }

        public string Description
        {
            get
            {
                return m_entry.Content.Content;
            }
            private set
            {
                m_entry.Content.Content = value;
            }
        }

        public string Location
        {
            get
            {
                if (null == m_locationStringCache)
                {
                    m_locationStringCache = m_entry.Locations.GetLocationString();
                }
                return m_locationStringCache;
            }
        }

        //public DateTime StartTime
        //{
        //    get
        //    {
        //        return m_when.StartTime;
        //    }
        //}

        //public DateTime EndTime
        //{
        //    get
        //    {
        //        return m_when.EndTime;
        //    }
        //}

        public bool IsAllDay
        {
            get
            {
                return m_when.AllDay;
            }
        }

        public string DisplayYear
        {
            get
            {
                return m_when.StartTime.Year.ToString();
            }
        }

        public string DisplayMonth
        {
            get
            {
                switch (m_when.StartTime.Month)
                {
                    case 1:
                        return "一月"; //"JAN";
                    case 2:
                        return "二月"; //"FEB";
                    case 3:
                        return "三月"; //"MAR";
                    case 4:
                        return "四月"; //"APR";
                    case 5:
                        return "五月"; //"MAY";
                    case 6:
                        return "六月"; //"JUN";
                    case 7:
                        return "七月"; //"JUL";
                    case 8:
                        return "八月"; //"AUG";
                    case 9:
                        return "九月"; //"SEP";
                    case 10:
                        return "十月"; //"OCT";
                    case 11:
                        return "十一月"; //"NOV";
                    case 12:
                        return "十二月"; //"DEC";
                    default:
                        return string.Empty;
                }
            }
        }

        public string DisplayDate
        {
            get
            {
                return m_when.StartTime.Day.ToString();
            }
        }

        public EventDataModel(GCalendar.EventEntry entry, When when)
        {
            m_entry = entry;
            m_when = when;
        }

        public GCalendar.EventEntry Update(EditEventModel editEventModel)
        {
            Title = editEventModel.Title;
            Description = editEventModel.Description;
            m_when.StartTime = editEventModel.StartTime;
            m_when.EndTime = editEventModel.EndTime;
            return m_entry.Update() as GCalendar.EventEntry;
        }
    }
}
